package com.yycx.module.user.provider.handler;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.SaveInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.module.user.client.entity.SysHtml;
import com.yycx.module.user.provider.service.SysHtmlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 协议保存
 *
 * @author zyf
 */
@Component
public class SysHtmlSaveHandler implements SaveInterceptor<SysHtml> {
    @Autowired
    private SysHtmlService sysHtmlService;

    @Override
    public ResultBody validate(CriteriaSave cs, EntityMap params) {
        SysHtml html = cs.getEntity(SysHtml.class);
        String htmlTitle = html.getHtmlTitle();
        if (FlymeUtils.isEmpty(htmlTitle)) {
            return ResultBody.failed("分类名称不能为空");
        }
        SysHtml prodCategory = sysHtmlService.getHtml(htmlTitle);
        if (FlymeUtils.isEmpty(prodCategory)) {
            return ResultBody.failed("分类已存在");
        }
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaSave cs, EntityMap params, SysHtml sysHtml) {

    }

}
